package my.springframework.bean.factory.support;

import my.springframework.bean.BeanException;
import my.springframework.bean.factory.BeanFactory;
import my.springframework.bean.factory.config.BeanDefinition;

/**
 * @author sk
 * @description
 * @since 2021-11-23
 **/
public abstract class AbstractBeanFactory extends DefaultSingletonBeanRegistry implements BeanFactory {


    @Override
    public Object getBean(String name) throws BeanException {
        Object bean = getSingleton(name);
        if (bean != null) {
            return bean;
        }

        BeanDefinition beanDefinition = getBeanDefinition(name);
        return createBean(name, beanDefinition);
    }

    protected abstract BeanDefinition getBeanDefinition(String name) throws BeanException;

    protected abstract Object createBean(String beanName, BeanDefinition beanDefinition) throws BeanException;
}
